package com.edt.ichannel.api.service.impl;

import com.edt.ichannel.api.common.constant.CommonConstant;
import com.edt.ichannel.api.dao.UnicomPayReqDao;
import com.edt.ichannel.api.entiy.local.UnicomPayReq;
import com.edt.ichannel.api.service.UnicomPayReqService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@Service
public class UnicomPayReqServiceImpl implements UnicomPayReqService {
    @Resource
    private UnicomPayReqDao unicomPayReqDao;
    @Override
    public void saveUnicomPayReqList(List<UnicomPayReq> unicomPayReqs) {
        if (unicomPayReqs != null){
            int count = CommonConstant.BRANCH_COUNT;
            int lastIndex = count ;
            for(int index = 0; index < unicomPayReqs.size();){
                if(lastIndex > unicomPayReqs.size()){
                    lastIndex = unicomPayReqs.size();
                    unicomPayReqDao.insertList(unicomPayReqs.subList(index,lastIndex));
                    break;
                }else{
                    unicomPayReqDao.insertList(unicomPayReqs.subList(index, lastIndex));
                    index = lastIndex;
                    lastIndex = index + (count);
                }
            }
            log.info("list 长度："+unicomPayReqs.size());
        }else{
            log.info("list为空");
        }
    }

    @Override
    public void updateToCallBackSuccess(String id) {
        unicomPayReqDao.updateToCallBackSuccess(id);
    }

    @Override
    public void updateToCallBackFail(String id) {
        unicomPayReqDao.updateToCallBackFail(id);
    }
}
